// pages/home/components/modelstyle/modelstyle.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
   "modelstyle":{type:Object }
  },

  /**
   * 组件的初始数据
   */
  data: {
    brand:'',
    ar:2,
    bgimg:''
  },
  attached() {
this.changimg();
    app.func.getPromise('/list/shortcut')
        .then(([code, res]) => {
            this.setData({brand: res.data});
        });


        app.func.getPromise('/list/zone')
    .then(([code, res]) => {
        this.setData({zone: res.data});
        let arr =[]
        this.data.zone.forEach((item,index) =>{
          console.log(item)
          console.log(index)
          arr.push(item.sku)
          this.setData({
            sku:arr
          });
        })
        console.log(this.data.sku)
    })
   
},

  /**
   * 组件的方法列表
   */
  methods: {
    //搜索
    search: function () {
      wx.navigateTo({
          url: "/pages/index/search/search"
      })
  },
  brandsku: function (e) {
    let item = e.currentTarget.dataset.item;
    console.log(item)
    switch (item[`link_type`]){
      case 0:
        let id = item[`category_id`];
        // wx.setStorage({key:"ca【【【【tegory_id", id})旧
        wx.setStorageSync('category_id', id)
        let extConfig = wx.getExtConfigSync? wx.getExtConfigSync(): {} ;
        if(extConfig.category = null || extConfig.category == 0) {
          wx.navigateTo({
            url: '/pages/index/categorysku/categorysku',
          })
        } else {
          wx.navigateTo({
            url: '/pages/index/newcategory/newcategory?id=' + id,
          })
        }
        break;
      case 1:
        wx.navigateTo({
          url:'/pages/index/brandsku/brandsku?id=' + item['topic_id']
        })
        break;
      case 2:
        break;
    }
  },
  productdetail: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/productdetail/productdetail?id=' + id
    })
  },
  addcart:function(e){
    console.log('111')
    console.log(this.data.gifts)
      let id = e.currentTarget.dataset.id;
          app.func.postPromise('/addcartv2',
                  {
                      pro_id:id,
                      count:1
                  })  .then(([code, res]) => {
                      console.log(res);
                      if(code == 200){
                          app.func.toastPromise('加入购物车成功','none',  500)
                          .then(()=>{
                        
                          })
                          this.setData({
                            noaddcart:false
                          })
                      }else{
                          wx.showToast({
                            title:res.message,
                            icon:'none',
                            mask:true
                          })
                      }
                  })
  
  },
 changimg(){
  console.log(this.properties.modelstyle)
          let arr =['https://files.dianlinet.com/dianli/images/2021-03-23/14-18-31.jpg',
                    'https://files.dianlinet.com/dianli/images/2021-03-23/17-18-36.jpg'
        ];
        if(this.properties.modelstyle.type =='Dragon'){
          let bgimg = arr[0];
          this.setData({
              bgimg :bgimg
          })
        }
        if(this.properties.modelstyle.type =='summer'){
          let bgimgs = arr[1];
          this.setData({
              bgimg :bgimgs
          })
        }
  }
  }
})
